<?php
//Include database connection page
include '..'.DIRECTORY_SEPARATOR.'db-connection'.DIRECTORY_SEPARATOR.'conn.php';

try {
	//var_dump($_FILES);
	
	$target = "..".DIRECTORY_SEPARATOR."videos".DIRECTORY_SEPARATOR.""; 
 	
	$thumbTarget = $target . basename($_FILES['uploadedThumb']['name']) ;
	
	$target = $target . basename($_FILES['uploaded']['name']) ;
 		
 	
 	//echo "<br><br>"; 
 	//echo "target = ". $target;
 	//echo "<br><br>";
 	//var_dump($_FILES);
 	$ok=1; 
 	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
 	{
 		if(move_uploaded_file($_FILES['uploadedThumb']['tmp_name'], $thumbTarget))
 		{
	 		//video path, video thumbnail path,category id, sub category id,video title, video desc,keywords, video mode (public/private)
	 		$videoPath = $target;
	 		$videoThumbPath = $thumbTarget;
	 		$categoryId = $_REQUEST["ddlcategoryName"];
	 		$subcategoryId = $_REQUEST["ddlSubcategoryName"]; 		
	 		$videoTitle = $_REQUEST["txt_vid_title"];
	 		$videoDesc = $_REQUEST["txtarea_vid_desc"];
	 		$keywords = $_REQUEST["txtarea_vid_keywords"];
	 		$videoMode = $_REQUEST["video_view_mode_pub"];
	 		$videoMode = "N";
	 		$userId = $_SESSION['userid'];
	 		//echo $categoryId . " -- " . $videoTitle . " -- " . $videoDesc . " -- " .$keywords . " -- ". $videoMode . " --";
	 		//echo "<br><br>";
	 		$sql = "INSERT INTO tbl_video_master(`txt_video_title`, `txt_video_desc`, `int_uploader_user_id`, `txt_video_path`, `txt_thumb_video_path`, `yn_is_approved`, `int_cat_id`, `int_sub_cat_id`, `txt_keywords`, `yn_is_public`) VALUES ('".$videoTitle."','".$videoDesc."','".$userId."','".$videoPath."','".$videoThumbPath."','N','".$categoryId."','".$subcategoryId."','".$keywords."','".$videoMode."')";
	 		//echo "<br><br>";
	 		//echo "<br><br>";
	 		//echo $sql;
	 		//echo "<br><br>";
	 		//echo "<br><br>";
	 		$result = mysql_query($sql);
	 		//echo "result is - " . $result;
	 		echo "The file --  ". basename( $_FILES['uploaded']['name']). " has been uploaded successfully.";
	 		header("Location: admin-homepage.php?page=see-all-videos&u=succes");
 		}else{
 			echo "Sorry, there was a problem uploading your thumbnail video file.";
 		} 		
 	} else {
 		echo "Sorry, there was a problem uploading your main video file.";
 	}
} catch (Exception $e) {
	echo "Exception from upload videos - " . $e;
}
		
 

?>